﻿// <copyright file="TestUpdateService.cs" company="Mooville">
//   Copyright © 2010 Roger Deetz. All rights reserved.
// </copyright>

namespace Mooville.Common.Testing.Mocks
{
    using System;
    using Mooville.Common.Updates;

    public class TestUpdateService : IUpdateService
    {
        public const string DefaultTestAddress = @"http://www.mooville.com";
        public const string DefaultTestExceptionMessage = @"Cannot check for updates.";
        private UpdateResultType testResultType;

        public TestUpdateService()
            : this(UpdateResultType.NoUpdateAvailable)
        {
        }

        public TestUpdateService(UpdateResultType testResultType)
        {
            this.testResultType = testResultType;
        }

        #region IUpdateService Members

        public UpdateResult CheckForUpdates(string product, string version)
        {
            UpdateResult result = new UpdateResult();
            result.ResultType = this.testResultType;

            switch (this.testResultType)
            {
                case UpdateResultType.Error:
                    result.Exception = new InvalidOperationException(TestUpdateService.DefaultTestExceptionMessage);
                    break;
                case UpdateResultType.NoUpdateAvailable:
                    break;
                case UpdateResultType.UpdateAvailable:
                    result.Address = TestUpdateService.DefaultTestAddress;
                    break;
                default:
                    break;
            }

            return result;
        }

        #endregion
    }
}
